<?php
namespace App\Libraries\Decorator\Image;


use App\Libraries\Decorator\DecoratorInterface\ModelDecorator;
use App\Libraries\Tools\URL;

class CoverDecorator implements ModelDecorator
{

    public function before(){
        //todo
    }

    public function after(&$data){
        if(!is_array($data)){
            $data = json_decode(json_encode($data), true);
        }
        if (isset($data['cover'])) {
            // 一维数组
            $data['cover'] = URL::getImage($data['cover']);
        }
        if(is_array($data)){
            foreach($data as &$v){
                $this->after($v);
            }
        }
        return $data;
    }
}